package com.ljh.redis.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Themberfue
 * @date: 2025/4/5 15:20
 * @description:
 */
@RestController
public class ListController {
    @Autowired
    StringRedisTemplate redisTemplate;

    @GetMapping("/list")
    public List<String> list() {
        redisTemplate.execute((RedisConnection connection) -> {
            connection.flushAll();
            return null;
        });

        redisTemplate.opsForList().leftPush("k1", "111");
        redisTemplate.opsForList().leftPushAll("k1", "222", "333", "444");

        redisTemplate.opsForList().leftPop("k1");

        return redisTemplate.opsForList().range("k1", 0, -1);
    }
}
